package com.jy.datapipeline.export.controller;

import com.jy.datapipeline.export.service.ExpTaskExecuteLogService;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping(value = "/exptask/execute/")
public class ExpTaskExecuteLogController {
    @Autowired
    private ExpTaskExecuteLogService expTaskExecuteLogService;

    @RequestMapping( value = "findByList",method = RequestMethod.GET)
    @ResponseBody
    public Object findDataStoreByList(
        @RequestParam(value = "taskId",required = true) String taskId,
        @RequestParam(value = "status",required = true) String status,
        @RequestParam(value = "iDisplayStart",required = true) Integer iDisplayStart,
        @RequestParam(value = "iDisplayLength",required = true) Integer iDisplayLength
    ){
        Map<String, Object> map=new HashMap<>();
        List<Map<String,Object>> list=this.expTaskExecuteLogService.findExpTaskExecuteLogByList(taskId,iDisplayStart,iDisplayLength,status);
        Integer count=this.expTaskExecuteLogService.findExpTaskExecuteLogByCount(taskId,status);
        map.put("datalist",list);
        map.put("count", count);
        return map;
    }

    @RequestMapping( value = "deleteByTaskExecutelogId",method = RequestMethod.POST)
    @ResponseBody
    public Object deleteByTaskExecutelogId(
        @RequestParam(value = "taskExecutelogId",required = true) String taskExecutelogId
    ){
        Map<String, Object> result=new HashMap<>();
        try {
           boolean flag= this.expTaskExecuteLogService.deleteByTaskExecutelogId(taskExecutelogId);
            result.put("status", flag);
            result.put("msg", "success");
        }catch (Exception e){
            result.put("status", false);
            result.put("msg", "删除异常["+e.getMessage()+"]");
        }

        return result;
    }


}
